import { Grid } from "@nutui/nutui-react-taro";
import { Image, View } from "@tarojs/components";
import Taro from "@tarojs/taro";
import { useRequest } from "ahooks";
import CommonTitle from "../../components/CommonTitle";
import { getUserInfoApi } from "../../servers/servers";
import kaimenPng from "./image/kaimen.png";
import bangdingdianchi from "./image/bangdingdianchi.png";
import fazhanPng from "./image/fazhan.png";
import jiebangdianchi from "./image/jiebangdianchi.png";
import userPng from "./image/user.png";
import youhuiquanPng from "./image/youhuiquan.png";
import yuqiPng from "./image/yuqi.png";
import zukePng from "./image/zuke.png";
import bangdingyonghu from "./image/bangdingyonghu.png";
import logPng from "./image/log.png";
import zhuantaiPng from './image/zhaungtai.png'


export default () => {
  // 个人信息
  const { data: userPermissCodes } = useRequest(async () => {
    const _res = await getUserInfoApi();
    return _res?.data?.permissions?.map((e) => e?.code);
  });

  console.log("userPermissCodes", userPermissCodes);
  return (
    <View className="index">
      {[1, 2, 3, 7, 8]?.every(
        (e) => !(userPermissCodes ?? []).includes(e)
      ) ? null : (
        <CommonTitle title="换电功能" />
      )}

      <Grid columns="3" square>
        {(userPermissCodes ?? [])?.includes(1) && (
          <Grid.Item
            text="用户信息查询"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/check/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={userPng}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}

        {(userPermissCodes ?? [])?.includes(2) && (
          <Grid.Item
            text="用户渠道绑定"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/binding/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={bangdingyonghu}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}

        {(userPermissCodes ?? [])?.includes(3) && (
          <Grid.Item
            text="优惠券发放"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/coupon/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={youhuiquanPng}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}
        {(userPermissCodes ?? [])?.includes(7) && (
          <Grid.Item
            text="绑定电池"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/bangdingdianchi/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={bangdingdianchi}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}

        {(userPermissCodes ?? [])?.includes(8) && (
          <Grid.Item
            text="解绑电池"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/jiebangdianchi/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={jiebangdianchi}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}

        <Grid.Item
          text="电池查询"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/cart/batteryStatus/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={zhuantaiPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>

        <Grid.Item
          text="开仓退电池"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/cart/batteryExchangeCabinet/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={kaimenPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>
      </Grid>

      {[4, 5, 6]?.every((e) => !(userPermissCodes ?? []).includes(e)) ? null : (
        <CommonTitle title="换电数据" />
      )}

      <Grid columns="3" square>
        {(userPermissCodes ?? [])?.includes(4) && (
          <Grid.Item
            text="发展用户"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/pipeline/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={fazhanPng}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}

        {(userPermissCodes ?? [])?.includes(5) && (
          <Grid.Item
            text="单电用户"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/lease/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={zukePng}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}

        {(userPermissCodes ?? [])?.includes(5) && (
          <Grid.Item
            text="车电用户"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/dianchi/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={zukePng}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}

        {(userPermissCodes ?? [])?.includes(6) && (
          <Grid.Item
            text="逾期用户"
            onClick={() => {
              Taro.navigateTo({
                url: `/pages/cart/overdue/index`,
              });
            }}
          >
            <Image
              mode="aspectFit"
              radius="50%"
              src={yuqiPng}
              style={{
                width: 40,
              }}
            />
          </Grid.Item>
        )}
      </Grid>

      <CommonTitle title="操作日志" />

      <Grid columns="3" square>
        <Grid.Item
          text="用户查询历史"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/cart/check/checkLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>

        <Grid.Item
          text="用户渠道绑定历史"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/cart/binding/bingdinLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>

        <Grid.Item
          text="优惠券发放历史"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/cart/coupon/couponLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>

        {/* <Grid.Item
          text="电池查询历史"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/cart/dianchiLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item> */}

        <Grid.Item
          text="渠道转个人历史"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/commonLog/channelLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>

        {/* <Grid.Item
          text="消除逾期历史"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/commonLog/overdueLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item> */}

        <Grid.Item
          text="绑定电池记录"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/commonLog/bindingLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>
        <Grid.Item
          text="解绑电池记录"
          onClick={() => {
            Taro.navigateTo({
              url: `/pages/commonLog/unbindLog/index`,
            });
          }}
        >
          <Image
            mode="aspectFit"
            radius="50%"
            src={logPng}
            style={{
              width: 40,
            }}
          />
        </Grid.Item>
      </Grid>
    </View>
  );
};
